<?php

$str = "student. a am I";

echo reverseSentence($str);

function reverseSentence($str){

    //1.字符串变成数组
    $arr = explode(" ", $str);


//    $result = '';
//    for($i= count($arr) - 1; $i >= 0; $i--){
//        $result .= $arr[$i]." ";
//    }

    //2.数组倒序
    $reverseArr = array_reverse($arr);

    //3.数组变成字符串

    return join(" ", $reverseArr);
}
